<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <router-link to="/home">Home</router-link>
        <router-link to="/film/123">Film1</router-link>
        <router-link to="/film/456">Film2</router-link>
        <router-link to="/card">Card</router-link>
        <router-view></router-view>
    </div>
</body>
<script src="./node_modules/vue/dist/vue.js"></script>
<script src="./node_modules/vue-router/dist/vue-router.js"></script>
<script>
    // let Home = {
    //     template:`<h1>这是Home组件</h1>`,
    // }
    let routes = [
        {
            path:"/home",
            component:()=>import('./components/home.js'),
        },
        {
            path:"/film/:filmId",
            component:()=>import('./components/film.js'),
            beforeEnter: (to, from, next) => {
                console.log("路由独享的导航守卫");
                next();
            }
        },
        {
            path:"/card",
            component:()=>import('./components/card.js'),
        },
        {
            path:"*",
            redirect:"/home",
        }
    ];
    let router = new VueRouter({
        routes,
    });
    router.beforeEach((to, from, next) => {
        console.log("全局守卫");
        next();
    });
 


    let vm = new Vue({
        el:"#app",
        router,
    })
</script>
</html>